package javabase.collection.list.serializable;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ArraySerial {

	// 数组序列化时，不管是否有值，都会将整个数组序列化到文件中
	public static void main(String[] args) {
	    String[] stra = new String[4];
		stra[0] = "0000000000";
		stra[2] = "2222222222";
		File file = new File("array.out");
		ObjectOutputStream oos = null;
		ObjectInputStream ois = null;
		try {
			oos = new ObjectOutputStream(new FileOutputStream(file));
			oos.writeObject(stra);
			
			ois = new ObjectInputStream(new FileInputStream(file));
			String[] str  = (String[])ois.readObject();
			for(String s: str)
			{
				System.out.println(s);
			}
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			try {
				oos.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				ois.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
